using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class RankPanel : BasePanel<RankPanel>
{
    public MyGUIButton button;
    public GameObject nameParent;
    public GameObject scoreParent;
    public GameObject timeParent;
    private MyGUILable[] labName;
    private MyGUILable[] labScore;
    private MyGUILable[] labTime;
    void Start()
    {
        labName = nameParent.GetComponentsInChildren<MyGUILable>();
        labScore = scoreParent.GetComponentsInChildren<MyGUILable>();
        labTime = timeParent.GetComponentsInChildren<MyGUILable>();
        button.onClick += () =>
        {
            HidePanel();
            BeginPanel.Instance.ShowPanel();
        };
        HidePanel();
    }
    public override void ShowPanel()
    {
        base.ShowPanel();
        UpdatePanelInfo();
    }
    //排行榜更新
    public void UpdatePanelInfo()
    {
        List<RankInfo> list = GameDataManager.Instance.rankData.list;
        for (int i = 0; i < list.Count; i++)
        {
            labName[i].content.text = list[i].name;
            labScore[i].content.text = list[i].score.ToString();
            labTime[i].content.text = "";
            int time = (int)list[i].time;
            if (time / 3600 > 0)
            {
                labTime[i].content.text += time / 3600 + "h";
            }
            if (time % 3600 / 60 > 0 || labTime[i].content.text != "")
            {
                labTime[i].content.text += time % 3600 / 60 + "m";
            }
            labTime[i].content.text += time % 60 + "s";
        }
    }
}
